﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mono.Cecil;
using Mono.Cecil.Cil;

namespace devtm.Aop.Extensions
{
    
    public static class InstructionExt
    {


        public static bool IsJump(this Instruction instruction) { return cdeJump.Contains(instruction.OpCode.Code); }
        
        private static Code[] cdeJump = new Code[] { Code.Beq, Code.Beq_S, Code.Bge, Code.Bge_S, Code.Bge_Un, Code.Bge_Un_S, Code.Bgt, Code.Bgt_S, Code.Bgt_Un, Code.Bgt_Un_S, Code.Ble, Code.Ble_S, Code.Ble_Un, Code.Ble_Un_S, Code.Blt, Code.Blt_S, Code.Blt_Un, Code.Blt_Un_S, Code.Bne_Un, Code.Bne_Un_S, Code.Leave, Code.Leave_S, Code.Br, Code.Br_S, Code.Brfalse, Code.Brfalse_S, Code.Brtrue, Code.Brtrue_S };

        public static bool IsThrow(this Instruction instruction) { return instruction.OpCode.Code == Code.Throw; }

        public static bool IsRet(this Instruction instruction) { return instruction.OpCode.Code == Code.Ret; }

        public static bool IsBr(this Instruction instruction) { return instruction.OpCode.Code == Code.Br || instruction.OpCode.Code == Code.Br_S; }
        
        public static bool IsBrConditionnal(this Instruction instruction) { return instruction.OpCode.Code == Code.Brtrue || instruction.OpCode.Code == Code.Brtrue_S || instruction.OpCode.Code == Code.Brfalse || instruction.OpCode.Code == Code.Brfalse_S; }

        public static bool IsLeave(this Instruction instruction) { return instruction.OpCode.Code == Code.Leave || instruction.OpCode.Code == Code.Leave_S; }


    }
}
